package com.jwsoft.manager.core.gateway.controller;

import com.jwsoft.manager.common.vo.eduTalentPool.eduTalentPool.EduTalentPoolVO;
import com.jwsoft.manager.common.vo.eduTalentPool.eduTalentPool.EduTalentPoolKeyVO;
import com.jwsoft.manager.common.vo.eduTalentPool.eduTalentPool.EduTalentPoolQueryVO;
import com.jwsoft.manager.core.integration.EduTalentPoolIntegration;
import com.jwsoft.manager.common.vo.eduTalentPool.eduTalentPool.EduTalentPoolImpFileVO;
import com.github.pagehelper.PageInfo;
import org.springframework.web.multipart.MultipartFile;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.module.base.core.utils.ServiceRequestUtil;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.fastjson2.JSON;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.AccessLimited;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import org.springframework.validation.annotation.Validated;
import com.bifang.assistant.common.constants.Validators;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.List;
/**
* 人才库信息 网关
*
* @author chenzh 845078693@qq.com
* @since 1.0.0 2025-05-07
*/
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "人才库信息", description = "人才库信息")
public class  EduTalentPoolController {

    @Autowired
    public EduTalentPoolIntegration eduTalentPoolIntegration;

    @Operation(summary = "人才库信息分页查询",description = "人才库信息分页查询")
    @PostMapping(value = "/eduTalentPool0001", produces = "application/json;charset=UTF-8")
    @AccessLimited(maxTimes=10,duration = "PT2S")
    public AppResponse<PageInfo<EduTalentPoolVO>> getList(@RequestBody @Validated EduTalentPoolQueryVO vo) {
        return AppResponse.successData(eduTalentPoolIntegration.getList(vo));
    }

    @Operation(summary = "人才库信息查询详情",description = "人才库信息查询详情")
    @PostMapping(value = "/eduTalentPool0002", produces = "application/json;charset=UTF-8")
    @AccessLimited(maxTimes=10,duration = "PT2S")
    public AppResponse<EduTalentPoolVO> getById(@RequestBody @Validated EduTalentPoolKeyVO vo) {
        return AppResponse.successData(eduTalentPoolIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息新增",description = "人才库信息新增")
    @PostMapping(value = "/eduTalentPool0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentPoolVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduTalentPoolVO vo) {
        return AppResponse.successData(eduTalentPoolIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息修改",description = "人才库信息修改")
    @PostMapping(value = "/eduTalentPool0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduTalentPoolVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduTalentPoolVO vo) {
        return AppResponse.successData(eduTalentPoolIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息删除",description = "人才库信息删除")
    @PostMapping(value = "/eduTalentPool0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduTalentPoolKeyVO vo) {
        eduTalentPoolIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }
    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息批量删除",description = "人才库信息批量删除")
    @PostMapping(value = "/eduTalentPool0007", produces = "application/json;charset=UTF-8")
    public AppResponse delBatch(@RequestBody @Validated EduTalentPoolKeyVO vo) {
        eduTalentPoolIntegration.delBatch(vo);
        return AppResponse.successMsg("删除成功！");
    }
    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息导入模板下载", description = "人才库信息导入模板下载")
    @PostMapping(value = "/eduTalentPool0008")
    public void downloadModel(
        HttpServletRequest request,
        @RequestParam Map<String ,Object> paramMap,
        @RequestBody(required = false) String body,
        HttpServletResponse response) {
        ExcelVO vo = null;
        if (StringUtils.isNotBlank(body)) {
            vo = JSON.parseObject(body, ExcelVO.class);
        } else {
            vo = new ExcelVO();
            if (paramMap.get("modelCode") != null) {
                vo.setModelCode(paramMap.get("modelCode").toString());
            }
            if (paramMap.get("excelVersion") != null) {
                vo.setExcelVersion(paramMap.get("excelVersion").toString());
            }
            if (paramMap.get("rows") != null) {
                vo.setRows(Integer.parseInt(paramMap.get("rows").toString()));
            }
            if (paramMap.get("dictMap") != null) {
                vo.setDictMap((Map<String , List<SelectVO>>) JSON.parse(JSON.toJSONString(paramMap.get("dictMap"))));
            }
        }
        vo.setAccessToken(ServiceRequestUtil.getAccessToken(request, response));
        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduTalentPoolIntegration.downloadModel(vo, response);
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "人才库信息数据导入", description = "人才库信息数据导入")
    @PostMapping(value = "/eduTalentPool0009")
    @NoSignCrypto
    public AppResponse<EduTalentPoolImpFileVO> impExcel(
        EduTalentPoolImpFileVO vo, @RequestParam("file") MultipartFile file) {
        return AppResponse.successData(eduTalentPoolIntegration.impExcel(vo, file));
    }

    @Idempotent(expire = "PT10S") //2秒内防重复提交
    @Operation(summary = "人才库信息数据导出", description = "人才库信息数据导出")
    @PostMapping(value = "/eduTalentPool0010", produces = "application/json;charset=UTF-8")
    public void expExcel(@RequestBody @Validated EduTalentPoolQueryVO vo, HttpServletResponse response) {
        eduTalentPoolIntegration.expExcel(vo, response);
    }
}
